//
//  PGZWindow.m
//  iMAL
//
//  Created by Stefano Pigozzi on 2/4/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "PGZWindow.h"


@implementation PGZWindow

@synthesize scrollView;

- (void) awakeFromNib
{	
	[self setDelegate:self];
}

- (NSSize)windowWillResize:(NSWindow *) window toSize:(NSSize)newSize
{
	NSPoint new_pos = [[scrollView contentView] bounds].origin;
	if(new_pos.x > 0.0 || new_pos.y > 0.0){
		self->pos = new_pos;
	}
	//float new_pos = [[scrollView contentView] bounds].origin.y;
//	if (new_pos > 0.0){
//		self->position = new_pos;
//	} else {
//		[[scrollView contentView] scrollToPoint:NSMakePoint(0,self->position)];
//		[scrollView reflectScrolledClipView: [scrollView contentView]];
//	}
	
	if([window showsResizeIndicator])
		return newSize; //resize happens
	else
		return [window frame].size; //no change
}

- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame
{
	//let the zoom happen iff showsResizeIndicator is YES
	return [window showsResizeIndicator];
}

- (void)setResizable: (BOOL)resizable {
	[[self standardWindowButton:NSWindowZoomButton] setHidden:!resizable];
	[self setShowsResizeIndicator:resizable];
}

- (void)windowDidResize:(NSNotification *)notification
{
	NSPoint new_pos = [[scrollView contentView] bounds].origin;
	if(new_pos.x > 0.0 || new_pos.y > 0.0){
		self->pos = new_pos;
	} else {
		[[scrollView contentView] scrollToPoint:self->pos];
		[scrollView reflectScrolledClipView: [scrollView contentView]];	
	}
	self->pos = NSMakePoint(0.0, 0.0);
}

@end
